*** Stata program to create tables and figures using military and register data in the paper:
*** "Can Gender Attitudes Change? The Effect of Randomly Assigning
***   Women to Traditionally Male Teams"
*** by Gordon Dahl, Andreas Kotsadam, Dan-Olof Rooth
*** Data are subject to confidentiality restrictions, and so are not available for posting online
*** Last updated: December 2020

*******************************************************************************
********* Analysis to create tables and figures *******************************
*******************************************************************************

capture log close
log using Tables, replace text

**** Tables and columns using survey data 

use Analysis_data_coded_w1w2w3, replace
set more on

global xvars "ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works*"

* Table II: OLS estimates
* NOTE: Do not cluster by room here, because rooms have not yet been assigned
foreach outcome in team hhwork gident {
  xi: reg `outcome'_w1 $xvars if male==1
  testparm $xvars
}
 
* Table III: Test of random assignment
 * NOTE: Do not need to cluster by room here (although note that results are fairly similar with clustering)
  xi: reg fem_room_ind $xvars best_troop* if base_sample
  testparm $xvars
  sum fem_room_ind if base_sample 	
  
  
* Table IV: Experimental estimates of gender attitudes at wave 2 (added e(sample) to be used in Tables below)

foreach outcome in team hhwork gident {
  xi: reg `outcome'_w2 fem_room_ind i.`outcome'_w1_cwith0 best_troop* if base_sample, cl(room)
  gen sample_`outcome'=e(sample)
  xi: reg `outcome'_w2 fem_room_ind i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room) 
  sum `outcome'_w2 if base_sample & fem_room_ind==0
}

* Table V: Military outcomes measured at wave 2, that is, after boot camp
  
xi: reg q10_w2_qual fem_room_ind i.q10_with0 best_troop* $xvars if base_sample, cl(room)
sum q10_w2_qual if base_sample & fem_room_ind==0  
  
xi: reg enjoy_military_12 fem_room_ind best_troop* $xvars if base_sample, cl(room)
sum enjoy_military_12 if base_sample & fem_room_ind==0

*xi: reg cont_military_w2 fem_room_ind i.q8_with0 best_troop* $xvars if base_sample, cl(room)
*sum cont_military_w2 if base_sample

*xi: reg enjoy_room_567 fem_room_ind best_troop* $xvars if base_sample, cl(room) 
*sum enjoy_room_567 if base_sample 

* women as happy with the room?
*sum enjoy_room_567 if male==0 & n_room>=5 & n_room<=7 & random_divisions==1 

* Table VI: Female leadership at wave 2 and 3 (leader=troop; leader2=highest level, leader3=foreign operations)

foreach outcome in leader leader2 leader3 {
  xi: reg `outcome'_w2 fem_room_ind i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
  sum `outcome'_w2 if base_sample & fem_room_ind==0
  xi: reg `outcome'_w3 fem_room_ind i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
  sum `outcome'_w3 if base_sample & fem_room_ind==0
}

* Table VII: Experimental estimates of gender attitudes at wave 3 
 
* generate difference btw wave 3 and wave 2 attitudes
gen dteam_w3w2=team_w3-team_w2
gen dgident_w3w2=gident_w3-gident_w2

foreach outcome in team gident {
  xi: reg `outcome'_w3 fem_room_ind i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
  sum `outcome'_w3 if base_sample & fem_room_ind==0
  xi: reg d`outcome'_w3w2 fem_room_ind i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
  sum d`outcome'_w3w2 if base_sample & fem_room_ind==0
}

* Table VIII: Military outcomes measured at wave 3

xi: reg q10_w3_qual fem_room_ind i.q10_with0 best_troop* $xvars if base_sample, cl(room)
sum q10_w3_qual if base_sample & fem_room_ind==0

xi: reg enjoy_military_12_w3 fem_room_ind best_troop* $xvars if base_sample, cl(room)
sum enjoy_military_12_w3 if base_sample & fem_room_ind==0



* Figure I: Distribution of gender attitudes for male recruits at baseline
* Appendix Figure A1: Distribution of gender attitudes for female recruits at baseline
preserve
* Panel A 
* Same sex teams (team)
gen sex_t=sex_team if sex_team!=0

* To obtain percent in the graph, normalize by the total number of men and women
egen num_m= count(male) if male==1 & n_room>=5 & n_room<=7 & random_divisions==1 & sex_t!=., by(sex_t)
egen num_f = count(male) if male==0 & n_room>=5 & n_room<=7 & random_divisions==1 & sex_t!=., by(sex_t)
egen n_m=count(male) if male==1 & n_room>=5 & n_room<=7 & random_divisions==1 & sex_t!=. 
egen n_f=count(male) if male==0 & n_room>=5 & n_room<=7 & random_divisions==1 & sex_t!=. 
 
gen share_sex_t_m = num_m  / n_m
gen share_sex_t_f = num_f  / n_f
 
gen sex_t_reg=sex_t
label define regions 1 `" "1" "Completely" "disagree" "' 2 "2" 3 "3" 4 "4" 5 "5" 6 "6" 7 `" "7" "Completely" "agree" "'
label values sex_t_reg regions

* Figure I:
graph bar share_sex_t_m, over(sex_t_reg, label(labsize(medlarge))) ytitle("Fraction", size(medlarge)) ///
ylabel(,nogrid labsize(medlarge)) bar(1, color(gs6)) bar(1, lcolor(gs6)) legend(off) graphregion(color(white))


* Appendix Figure A1:
graph bar share_sex_t_f, over(sex_t_reg, label(labsize(medlarge))) ytitle("Fraction", size(medlarge)) ///
ylabel(,nogrid labsize(medlarge)) bar(1, color(gs6)) bar(1, lcolor(gs6)) legend(off) graphregion(color(white))


restore
* Panel B
* Share HH work (hhwork)

preserve

* To obtain percent in the graph, normalize by the total number of men and women
egen num_m= count(male) if male==1 & n_room>=5 & n_room<=7 & random_divisions==1 & q25_1!=., by(q25_1)
egen num_f = count(male) if male==0 & n_room>=5 & n_room<=7 & random_divisions==1 & q25_1!=., by(q25_1)
 
egen n_m=count(male) if male==1 & n_room>=5 & n_room<=7 & random_divisions==1 & q25_1!=. 
egen n_f=count(male) if male==0 & n_room>=5 & n_room<=7 & random_divisions==1 & q25_1!=. 
 
gen share_hhw_m = num_m  / n_m
gen share_hhw_f = num_f  / n_f

gen hhw_reg=q25_1
label define regions 1 `" "Strongly" "agree" "' 2 "Agree" 3 `" "Neither agree" "nor disagree" "' 4 "Disagree" 5 `" "Strongly" "disagree" "'
label values hhw_reg regions

* Figure I:
graph bar share_hhw_m, over(hhw_reg, label(labsize(medlarge))) ytitle("Fraction", size(medlarge)) ///
ylabel(,nogrid labsize(medlarge)) bar(1, color(gs6)) bar(1, lcolor(gs6)) legend(off) graphregion(color(white))


* Appendix Figure A1:
graph bar share_hhw_f, over(hhw_reg, label(labsize(medlarge))) ytitle("Fraction", size(medlarge)) ///
ylabel(,nogrid labsize(medlarge)) bar(1, color(gs6)) bar(1, lcolor(gs6)) legend(off) graphregion(color(white))


restore
* Panel C
* Gender identity (gident)

preserve

* To obtain percent in the graph, normalize by the total number of men and women
egen num_m= count(male) if male==1 & n_room>=5 & n_room<=7 & random_divisions==1 & q3_11!=., by(q3_11)
egen num_f = count(male) if male==0 & n_room>=5 & n_room<=7 & random_divisions==1 & q3_11!=., by(q3_11)
 
egen n_m=count(male) if male==1 & n_room>=5 & n_room<=7 & random_divisions==1 & q3_11!=. 
egen n_f=count(male) if male==0 & n_room>=5 & n_room<=7 & random_divisions==1 & q3_11!=. 
 
gen share_q3_11_m = num_m  / n_m
gen share_q3_11_f = num_f  / n_f

gen q3_11_reg=q3_11
label define regions 1 `" "Does not" "fit at all" "' 2 `" "Does not" "fit well" "' 3 `" "Reasonable" "fit" "' 4 `" "Fits" "well" "' 5 `" "Fits" "completely" "'
label values q3_11_reg regions

* Figure I:
graph bar share_q3_11_m, over(q3_11_reg, label(labsize(medlarge))) ytitle("Fraction", size(medlarge)) ///
ylabel(,nogrid labsize(medlarge)) bar(1, color(gs6)) bar(1, lcolor(gs6)) legend(off) graphregion(color(white))


* Appendix Figure A1:
graph bar share_q3_11_f, over(q3_11_reg, label(labsize(medlarge))) ytitle("Fraction", size(medlarge)) ///
ylabel(,nogrid labsize(medlarge)) bar(1, color(gs6)) bar(1, lcolor(gs6)) legend(off) graphregion(color(white))

restore


* Figure II. Distribution of gender attitudes over time
preserve
keep	if base_sample==1

* Some variable creation:

gen team_all=1 if team_w1!=. & team_w2!=. & team_w3!=.
gen gident_all=1 if gident_w1!=. & gident_w2!=. & gident_w3!=.

gen team_two=1 if team_w1!=. & team_w2!=. 
gen gident_two=1 if gident_w1!=. & gident_w2!=. 

gen hhwork_two=1 if hhwork_w1!=. & hhwork_w2!=. 

cap drop ch_*
gen ch_team2=team_w2-team_w1 if team_two==1
gen ch_hhwork2=hhwork_w2-hhwork_w1 if hhwork_two==1
gen ch_gident2=gident_w2-gident_w1 if gident_two==1

gen ch_team3=team_w3-team_w1 if team_all==1
gen ch_gident3=gident_w3-gident_w1 if gident_all==1
	
drop wave 
	reshape long team_w hhwork_w gident_w ,  i(q1) j(wave)
	gen wave2=wave if wave<3

* Labelling and more variables

label define ww 1 "Baseline" 2 "Wave 2" 3 "Wave 3"

label values wave ww

label define ww2 1 "Baseline" 2 "Wave 2" 

label values wave2 ww2


	
	gen ww2=wave if wave>1
	label define www 2 "W2-W1"  3 "W3-W1" 
	
	gen ww2hh=ww2 if wave<3
	label define wwwhh 2 "Wave 2-baseline"  
	
label values ww2 www
label values ww2hh wwwhh

	gen ch_team=ch_team2 if wave==2
	replace ch_team=ch_team3 if wave==3

	gen ch_hhwork=ch_hhwork2 if wave==2
	replace ch_team=ch_team3 if wave==3

	gen ch_gident=ch_gident2 if wave==2
	replace ch_gident=ch_gident3 if wave==3
	
set scheme s1mono
* Panel A 
cibar team_w, over1(fem_room_ind)  over2(wave) graph(legend(order(1 "Control" 2 "Treated" ) region(lstyle(none)))ytitle(Fraction)ylabel(0 (0.2) 1) plotregion(lcolor(white)))
* Panel B
cibar hhwork_w, over1(fem_room_ind)  over2(wave2) graph(legend(order(1 "Control" 2 "Treated" ) region(lstyle(none))) ytitle(Fraction)ylabel(0 (0.2) 1) plotregion(lcolor(white)))  
* Panel C
cibar gident_w, over1(fem_room_ind)  over2(wave) graph(legend(order(1 "Control" 2 "Treated" ) region(lstyle(none))) ytitle(Fraction)ylabel(0 (0.2) 1) plotregion(lcolor(white))) 
 restore 
	

**************************************************************************
********************** ONLINE APPENDIX ***********************************
**************************************************************************

**** Tables and columns using survey data 

* Appendix Table A1: Summary Statistics

* Full sample
sum $xvars if male==1
sum $xvars if male==0

* Baseline sample
sum $xvars if n_room>=5 & n_room<=7 & random_divisions==1 & male==1
sum $xvars if n_room>=5 & n_room<=7 & random_divisions==1 & male==0

* Appendix Table A3: Placebo tests: prior attitudes

foreach outcome in team hhwork gident {
  xi: reg `outcome'_w1 fem_room_ind $xvars best_troop* if base_sample, cl(room) 
  sum `outcome'_w1 if base_sample & fem_room_ind==0
  }
 
* Appendix Table A4: Attrition in wave 2 and 3  

** wave 2
foreach outcome in team hhwork gident {
  xi: reg `outcome'_w2_miss fem_room_ind i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
  sum `outcome'_w2_miss if base_sample & fem_room_ind==0
 }

** wave 3
foreach outcome in team gident {
    xi: reg `outcome'_w3_miss fem_room_ind i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
  sum `outcome'_w3_miss if base_sample & fem_room_ind==0
}

* Appendix Table A5: Testing for differential attrition by baseline answers

** wave 2
foreach outcome in team hhwork gident {
  xi: reg `outcome'_w2_miss `outcome'_w1 $xvars  best_troop* if base_sample, cl(room)
  sum `outcome'_w2_miss if e(sample)==1 & fem_room_ind==0
 }
  ** wave 3
foreach outcome in team  gident {
  xi: reg `outcome'_w3_miss `outcome'_w1 $xvars  best_troop* if base_sample, cl(room)
  sum `outcome'_w3_miss if e(sample)==1 & fem_room_ind==0
 }

* Appendix Table A6: Additional military attitudes
xi: reg want_serve_w2 fem_room_ind i.want_serve_w1_cwith0 best_troop* $xvars if base_sample, cl(room)
sum want_serve_w2 if base_sample & fem_room_ind==0  
 
xi: reg enjoy_room_567 fem_room_ind best_troop* $xvars if base_sample, cl(room) 
sum enjoy_room_567 if base_sample & fem_room_ind==0

xi: reg cont_military_w2 fem_room_ind i.q8_with0 best_troop* $xvars if base_sample, cl(room)
sum cont_military_w2 if base_sample & fem_room_ind==0


xi: reg enjoy_room_567_w3 fem_room_ind best_troop* $xvars if base_sample, cl(room) 
sum enjoy_room_567_w3 if base_sample & fem_room_ind==0

xi: reg cont_military_w3 fem_room_ind i.q8_with0 best_troop* $xvars if base_sample, cl(room)
sum cont_military_w3 if base_sample & fem_room_ind==0


* Appendix Table A7: Robustness A-I

gen temp_sample=.

foreach outcome in team hhwork gident {
  * A. Baseline
  xi: reg `outcome'_w2 fem_room_ind i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
}
  * B. Lasso model 
* Must generate troop dummies that are non-missing within the specific samples
su best_troop*
cap gen FFI_TROPP_ID=.
forvalues v=1/42 {
cap replace FFI_TROPP_ID=`v' if best_troop`v'==1
}

 reg team_w2 fem_room_ind i.team_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works* best_troop* if base_sample, cl(room)
 tab FFI_TROPP_ID if e(sample)==1, gen(pds_tropp1_t)
  reg hhwork_w2 fem_room_ind i.team_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works* best_troop* if base_sample, cl(room)
 tab FFI_TROPP_ID if e(sample)==1, gen(pds_tropp1_h)
  reg gident_w2 fem_room_ind i.team_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works* best_troop* if base_sample, cl(room)
 tab FFI_TROPP_ID if e(sample)==1, gen(pds_tropp1_g)
 
 local vars "i.team_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works*"
 	pdslasso team_w2 fem_room_ind (`vars'##`vars' pds_tropp1_t*) if base_sample, pnotpen(pds_tropp1_t*) cl(room)
local vars "i.hhwork_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works*"
 	pdslasso hhwork_w2 fem_room_ind (`vars'##`vars' pds_tropp1_h*) if base_sample, pnotpen(pds_tropp1_h*) cl(room)
local vars "i.gident_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works*"
 	pdslasso gident_w2 fem_room_ind (`vars'##`vars' pds_tropp1_g*) if base_sample, pnotpen(pds_tropp1_g*) cl(room)
	
	foreach outcome in team hhwork gident {
  * C. Baseline w/o baseline attitudes & w/o controls
  xi: reg `outcome'_w2 fem_room_ind best_troop* if base_sample & sample_`outcome', cl(room)
  * D. Probit model
  xi: dprobit `outcome'_w2 fem_room_ind i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room) 
  * E. First difference model using binary scale
  xi: reg d`outcome' fem_room_ind $xvars best_troop* if base_sample, cl(room)
	}
	foreach outcome in team hhwork {
  * F. Baseline model using full scale
  xi: reg `outcome'_ordered_w2 fem_room_ind i.`outcome'_w1_cwith0 best_troop* if base_sample, cl(room)
	}
	foreach outcome in team hhwork gident {
  * G. First difference model using full scale
  xi: reg d`outcome'_fs_w2w1 fem_room_ind best_troop* if base_sample, cl(room)
  * H. 1 versus 2+ females
  xi: reg `outcome'_w2 fem_room_1 fem_room_2plus i.`outcome'_w1_cwith0 $xvars best_troop* i.n_room if base_sample, cl(room)
  * I. All room sizes
  replace temp_sample = male==1 & random_divisions==1
  xi: reg `outcome'_w2 fem_room_ind i.`outcome'_w1_cwith0 $xvars best_troop* if temp_sample, cl(room) 
  * J. Room size==6 & females==2
  replace temp_sample = male==1 & n_room==6 & (female_room==2 | female_room==0) & random_divisions==1
  xi: reg `outcome'_w2 fem_room_ind i.`outcome'_w1_cwith0 $xvars best_troop* if temp_sample, cl(room) 
  }

  * 
  
* Appendix Table A8: Heterogeneity by male characteristcs


* female friends, has sister, mom high ed, high muscle strength, hi IQ interactions
   
foreach outcome in team hhwork gident {
xi: reg `outcome'_w2 fem_room_ind fem_ffriends fem_ffriends_miss i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
xi: reg `outcome'_w2 fem_room_ind fem_has_sister fem_has_sister_miss i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
xi: reg `outcome'_w2 fem_room_ind fem_mom_edu_high fem_mom_edu_high_miss i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room) 
xi: reg `outcome'_w2 fem_room_ind fem_strength_high fem_strength_high_miss i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
xi: reg `outcome'_w2 fem_room_ind fem_IQ_high fem_IQ_high_miss i.`outcome'_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
  }

* Regressions with baseline negative stereotype interactions
** the "alternative" category now include the neutral response
xi: reg team_w2 fem_room_ind fem_ss_agree fem_ss_miss i.team_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
xi: reg hhwork_w2 fem_room_ind fem_hh_notshared fem_hh_miss i.hhwork_w1_cwith0 $xvars best_troop* if base_sample, cl(room)
xi: reg gident_w2 fem_room_ind fem_gi_masculine fem_gi_miss i.gident_w1_cwith0 $xvars best_troop* if base_sample, cl(room)


* Appendix Table A9: Experimental estimates of gender attitudes at wave 3 - NO XVARS
 
foreach outcome in team gident {
  xi: reg `outcome'_w3 fem_room_ind i.`outcome'_w1_cwith0 best_troop* if base_sample, cl(room)
  sum `outcome'_w3 if base_sample & fem_room_ind==0
  xi: reg d`outcome'_w3w2 fem_room_ind i.`outcome'_w1_cwith0 best_troop* if base_sample, cl(room)
  sum d`outcome'_w3w2 if base_sample & fem_room_ind==0
  }
  
* Appendix Table A10: Lasso
* Must generate troop dummies that are non-missing within the specific samples (Also for )
  reg team_w3 fem_room_ind i.team_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works* best_troop* if base_sample, cl(room)
 tab FFI_TROPP_ID if e(sample)==1, gen(pds_tropp3_t3)
  reg gident_w3 fem_room_ind i.team_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works* best_troop* if base_sample, cl(room)
 tab FFI_TROPP_ID if e(sample)==1, gen(pds_tropp3_g3)
 cap gen dteam_w3w2=team_w3-team_w2
cap gen dgident_w3w2=gident_w3-gident_w2
  reg dteam_w3w2 fem_room_ind i.team_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works* best_troop* if base_sample, cl(room)
 tab FFI_TROPP_ID if e(sample)==1, gen(pds_tropp4_t23)
  reg dgident_w3w2 fem_room_ind i.team_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works* best_troop* if base_sample, cl(room)
 tab FFI_TROPP_ID if e(sample)==1, gen(pds_tropp4_g23)

 local vars "i.team_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works*"
 	pdslasso team_w3 fem_room_ind (`vars'##`vars' pds_tropp3_t3*) if base_sample, pnotpen(pds_tropp3_t3*) cl(room)
local vars "i.gident_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works*"
 	pdslasso gident_w3 fem_room_ind (`vars'##`vars' pds_tropp3_g3*) if base_sample, pnotpen(pds_tropp3_g3*) cl(room)	
* Wave 3-2
local vars "i.team_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works*"
 	pdslasso dteam_w3w2 fem_room_ind (`vars'##`vars' pds_tropp4_t23*) if base_sample, pnotpen(pds_tropp4_t23*) cl(room)
local vars "i.gident_w1_cwith0 ffriends* has_sister* has_brother* strength_high* IQ_high* mom_edu_high* dad_edu_high* parents_divorced* mom_works*"
 	pdslasso dgident_w3w2 fem_room_ind (`vars'##`vars' pds_tropp4_g23*) if base_sample, pnotpen(pds_tropp4_g23*) cl(room)
	

 ******************* Appendix Figures *********************
 * Appendix Figure A1. See above 

* Appendix Figure A2. Comparison of attitudes in the general population versus in the military on the importance of sharing household work
* A. Gallup question on gender roles

use "Gallup_data.dta", replace
		 
* Make variable comparable to the one asked in the Military
recode hemmet (0/2=5) (3/4=4)  (5/6=3)  (7/8=2)  (9/10=1), gen(equality_not_important_cont) 


rename equality_not_important_cont hhw

* To obtain percent in the graph, normalize by the total number of men and women
egen num_m= count(male) if male==1 & hhw!=., by(hhw)
egen num_f = count(male) if male==0 & hhw!=., by(hhw)
 
 egen n_m=count(male) if male==1 & hhw!=. 
 egen n_f=count(male) if male==0 & hhw!=. 
 
 gen share_hhw_m = num_m  / n_m
 gen share_hhw_f = num_f  / n_f

 
gen hhw_reg=hhw
label define regions 1 `" "10" "Yes," "of course" "' 2 `"6-9"' 3 `"5"' 4 "1-4" 5 `" "0" "No," "not at all" "'

label values hhw_reg regions


* Men:
graph bar share_hhw_m  , ///
over(hhw_reg, label(labsize(medlarge))) ///
ytitle("Fraction", size(medlarge)) title("Male respondents", color(black) size(large)) ///
ylabel(0 .2 .4 .6 .8,nogrid labsize(medlarge)) bar(1, color(gs6)) bar(1, lcolor(gs6)) legend(off) graphregion(color(white))


* Women
graph bar share_hhw_f  , ///
over(hhw_reg, label(labsize(medlarge))) ///
ytitle("Fraction", size(medlarge)) title("Female respondents", color(black) size(large)) ///
ylabel(0 .2 .4 .6 .8,nogrid labsize(medlarge)) bar(1, color(gs6)) bar(1, lcolor(gs6)) legend(off) graphregion(color(white))


* B. Military question on gender roles:
use Analysis_data_coded_w1w2w3, replace

rename equality_not_important_cont hhw

* To obtain percent in the graph, normalize by the total number of men and women
egen num_m= count(male) if male==1 & n_room>=5 & n_room<=7 & random_divisions==1 & hhw!=., by(hhw)
egen num_f = count(male) if male==0 & n_room>=5 & n_room<=7 & random_divisions==1 & hhw!=., by(hhw)
 
 egen n_m=count(male) if male==1 & n_room>=5 & n_room<=7 & random_divisions==1 & hhw!=. 
 egen n_f=count(male) if male==0 & n_room>=5 & n_room<=7 & random_divisions==1 & hhw!=. 
 
 gen share_hhw_m = num_m  / n_m
 gen share_hhw_f = num_f  / n_f

 
gen hhw_reg=hhw
label define regions 1 `" "Strongly" "agree" "' 2 "Agree" 3 `" "Neither agree" "nor disagree" "' 4 "Disagree" 5 `" "Strongly" "disagree" "'
label values hhw_reg regions

* Men:
graph bar share_hhw_m  , ///
over(hhw_reg, label(labsize(medlarge))) ///
ytitle("Fraction", size(medlarge)) title("Male respondents", color(black) size(large)) ///
ylabel(0 .2 .4 .6 .8,nogrid labsize(medlarge)) bar(1, color(gs6)) bar(1, lcolor(gs6)) legend(off) graphregion(color(white))

* Women
graph bar share_hhw_f  , ///
over(hhw_reg, label(labsize(medlarge))) ///
ytitle("Fraction", size(medlarge)) title("Female respondents", color(black) size(large)) ///
ylabel(0 .2 .4 .6 .8,nogrid labsize(medlarge)) bar(1, color(gs6)) bar(1, lcolor(gs6)) legend(off) graphregion(color(white))


* Appendix Figure A3. Differences the full scale of responses between survey wave 2 and baseline attitudes.
use Analysis_data_coded_w1w2w3, replace

*create variables - can someone check these are right?
replace sex_team=. if sex_team==0
gen sex_team_w3=q29_w3

gen gidentc_w1 = q3_11
gen gidentc_w2 = q3_11_w2
gen gidentc_w3 = q3_11_w3

gen d_sex_team_w2 = -(sex_team_w2 - sex_team)
replace d_sex_team_w2=. if sex_team==0 | sex_team_w2==. | sex_team==.
gen d_sex_team_w3 = -(sex_team_w3 - sex_team)
replace d_sex_team_w3=. if sex_team==0 | sex_team_w3==. | sex_team==.

gen d_hhwork_ordered_w2 = hhwork_ordered_w2 - hhwork_ordered_w1

gen d_gidentc_w2 = gidentc_w2 - gidentc_w1
gen d_gidentc_w3 = gidentc_w3 - gidentc_w1

keep if base_sample==1


*5 difference variables for the graphs:
*d_sex_team_w2 d_sex_team_w3 d_hhwork_ordered_w2 d_gidentc_w2 d_gidentc_w3

*Goodman and Kruskal's gamma (measure of rank correlation for ordinal variables)
tab d_sex_team_w2 fem_room_ind, gamma
tab d_sex_team_w3 fem_room_ind, gamma
tab d_hhwork_ordered_w2 fem_room_ind, gamma
tab d_gidentc_w2 fem_room_ind, gamma
tab d_gidentc_w3 fem_room_ind, gamma

*Wave 2 - wave 1 graphs
twoway (histogram d_sex_team_w2 if fem_room_ind==1, discrete color(gray)) ///
       (histogram d_sex_team_w2 if fem_room_ind==0, discrete fcolor(none) lcolor(black)), ///
	   legend(order(1 "Treated" 2 "Control", size(medium)) region(style(none)) bmargin(tiny) ) ///
	   title("") graphregion(color(white)) xtitle("Difference", size(medium)) ytitle("Fraction", size(medium)) ///
	   caption("Test of equal ordinal rankings: Goodman-Kruskal gamma = .160** (.072)")  ///
	   xlabel(-6 -4 -2 0 2 4 6) ylabel(0(.1).3, nogrid)

twoway (histogram d_hhwork_ordered_w2 if fem_room_ind==1, discrete color(gray)) ///
       (histogram d_hhwork_ordered_w2 if fem_room_ind==0, discrete fcolor(none) lcolor(black)), ///
	   legend(order(1 "Treated" 2 "Control") region(style(none))) ///
	   title("") graphregion(color(white)) xtitle("Difference") ytitle("Fraction") ///
	   caption("Test of equal ordinal rankings: Goodman-Kruskal gamma = .196** (.082)")  ///
	   xlabel(-4 -2 0 2 4) ylabel(0(.1).6, nogrid) 

twoway (histogram d_gidentc_w2 if fem_room_ind==1, discrete color(gray)) ///
       (histogram d_gidentc_w2 if fem_room_ind==0, discrete color(none) lcolor(black)), ///
       legend(order(1 "Treated" 2 "Control") region(style(none))) ///
	   title("") graphregion(color(white)) xtitle("Difference") ytitle("Fraction") ///
	   caption("Test of equal ordinal rankings: Goodman-Kruskal gamma = .164* (.096)")  ///
	   xlabel(-4 -2 0 2 4) ylabel(0(.1).7, nogrid) 

* Appendix Figure A4. Differences the full scale of responses between survey wave 3 and baseline attitudes.	

*Wave 3 - wave 1 graphs
twoway (histogram d_sex_team_w3 if fem_room_ind==1, discrete color(gray)) ///
       (histogram d_sex_team_w3 if fem_room_ind==0, discrete fcolor(none) lcolor(black)), ///
	   legend(order(1 "Treated" 2 "Control") region(style(none))) ///
	   title("") graphregion(color(white)) xtitle("Difference") ytitle("Fraction") ///
	   caption("Test of equal ordinal rankings: Goodman-Kruskal gamma = .026 (.081)")  ///
	   xlabel(-6 -4 -2 0 2 4 6) ylabel(0(.1).3, nogrid)

twoway (histogram d_gidentc_w3 if fem_room_ind==1, discrete color(gray)) ///
       (histogram d_gidentc_w3 if fem_room_ind==0, discrete fcolor(none) lcolor(black)), ///
	   legend(order(1 "Treated" 2 "Control") region(style(none))) ///
	   title("") graphregion(color(white)) xtitle("Difference") ytitle("Fraction") ///
	   caption("Test of equal ordinal rankings: Goodman-Kruskal gamma = .008 (.107)")  ///
	   xlabel(-4 -2 0 2 4) ylabel(0(.1).7, nogrid) 
  

********************************************************************************************
********* Analysis to create main tables using register data *******************************
********************************************************************************************

**** Tables and columns using register data 

use Register_data, replace

* Table IV. Columns 7 and 8:
reg share_w_militaty_occ treated_female i.troop, cl(room)
reg share_w_militaty_occ treated_female i.troop *_wm *_mdum, cl(room)

* Table V, Column 3
reg vice_corporal treated_female i.troop *_wm *_mdum, cl(room)

* Table VII, Columns 5-7
foreach p in share_w_edu share_w_occup share_w_firm ///
{
reg `p' treated_female  i.troop *_wm *_mdum, cl(room)
su `p'  if treated_female==0
}



* Table VIII, Columns 3-7
 foreach p in high_average_grades high_conduct high_cooperation high_independence high_overall ///
{
reg `p' treated_female  i.troop *_wm *_mdum, cl(room)
su `p'  if treated_female==0
}


**********************************************************************************************
********************** ONLINE APPENDIX using register data ***********************************
**********************************************************************************************

**** Tables and columns using register data 
use Register_data.dta, replace
 
 * Appendix Table A2. Summary statistics for longer-run control variables
su share_women_hs_cohort gpa immigrant sister brother  share_w_occup_mor_15 share_w_occup_far_15 high_education_2010_mor  high_education_2010_far share_w_edu_mor share_w_edu_far

 
* Appendix Table A7: column 4  
* A
reg share_w_militaty_occ treated_female i.troop *_wm *_mdum, cl(room)
* B
  pdslasso share_w_militaty_occ treated_female (c.*_wm##c.*_wm *_mdum##*_mdum  tr_fe_*),  pnotpen(tr_fe_*) cl(room)
* H
recode n_fem_room (2/4=0), gen(one_female)
recode n_fem_room (1=0) (2/4=1), gen(more_female)
reg share_w_militaty_occ one_female more_female  i.troop *_wm *_mdum, cl(room)
* I
* Use a dataset containing more individuals than the base sample:
use Register_data_all, replace
reg share_w_militaty_occ treated_female  i.troop *_wm *_mdum, cl(room)
* J
recode n_fem_room (1 3/4=.), gen(two_fem)
 reg share_w_militaty_occ treated_female  i.troop *_wm *_mdum if n_room_original==6 & two_fem!=. , cl(room)
 

* Appendix Table A8. column 4  
  use Register_data, replace

* B
 cap gen treated_female_sis=treated_female*sister
reg share_w_militaty_occ treated_female  sister treated_female_sis i.troop *_wm *_mdum  , cl(room)

* C
  cap gen treated_female_mhe=treated_female*high_education_2010_mor
reg share_w_militaty_occ treated_female  high_education_2010_mor treated_female_mhe i.troop *_wm *_mdum  , cl(room)
* Table A9: columns 5-7 
foreach p in share_w_edu share_w_occup share_w_firm ///
{
reg `p' treated_female  i.troop , cl(room)
su `p'  if treated_female==0
}
* Table A10: columns 5-7  
foreach p in share_w_edu share_w_occup share_w_firm ///
{
  pdslasso `p'  treated_female (c.*_wm##c.*_wm *_mdum##*_mdum  tr_fe_*),  pnotpen(tr_fe_*) cl(room)
}

* Appendix Table A11. Commendations received during service
 foreach p in ln_aw_comm2 shoot_bronze  shoot_siver  ski_bronze  fieldsport_bronze  march_bronze  infantery_bronze  ///
{
reg `p' treated_female  i.troop *_wm *_mdum, cl(room)
su `p'  if treated_female==0
}

